#ifndef SMARTPHONE_H
#define SMARTPHONE_H

#include <QObject>
#include <QTimer>

#include "smartphonecore.h"
#include "../widgets/IncomingWidget.h"
#include "../widgets/CallWidget.h"

class Smartphone : public QObject
{
    Q_OBJECT
public:
    explicit Smartphone(QObject *parent = 0);
    ~Smartphone();
    static Smartphone *getInstance();

    void call(QString identity, MediaType mt, MediaDirection mdAudio, MediaDirection mdVideo);

    void startRecording();
    void stopRecording();
    void setRecordPath(QString path);
    void takePreviewSnapshot(long callid, QString path);

    void answer(long callid, MediaType mt, MediaDirection mdAudio, MediaDirection mdVideo);
    void terminate(long callid);
    int login(QString server_addr, SmartphoneTransportType portType,
              QString dispname, QString username, QString passwd, int expires);
    void logout();
    void refreshRegisters();
    int getCallsNb();
    void setRing(QString ring);
    void setCurrentCallid(long callid);
    long getCurrentCallid();
    void reloadMsPlugins(const QString path);
    void sendInfo(QString info, long callid);
    void setNativeWindowId(long id);
    void setNativePreviewWindowId(long id);

    void setStaticPicture(QString picture);
    void setStaticPictureFps(int fps);

    QVector<QString> getVideoDevices();
    void setVideoDevice(int id);

    QVector<QString> getCodecs(CodecType ct);
    void enableCodec(CodecType ct, int id, bool enabled);

    long createLocalPlayer(long windowid);
    void destroyPlayer(long player);
    void openPlayer(long player, QString filename);
    void closePlayer(long player);
    void startPlayer(long player);
    void pausePlayer(long player);
    /************回调函数,注意回调可能在主线线中也可以在单独线程中运行****************/
    void SmartphoneCallback(SmartphoneCallbackParam *param);


signals:
    void signalRegistrationStateChanged(SmartphoneState state, QString proxy, QString message);
    void signalCallStateChanged(SmartphoneState state, long callid, QString username, QString dispname, QString message);
private slots:
    void slotCallStateChanged(SmartphoneState state, long callid, QString username, QString dispname, QString message);
    void slotTimeOut();
private:
    int currentCallid;
    IncomingWidget *incomingWidget;
    CallWidget *callWidget;
    QTimer *timer;
};

#endif // SMARTPHONE_H
